#!/bin/sh
# Copyright (c) 2010, bkil.hu
# This program is free software and can be distributed under the terms of
# the GNU General Public License v2,
# see COPYING for detailed licensing terms.

# 2010-10-31 00:24

TRAPS="1 2 3 15"

cd $HOME/Videos ||exit 1
pidof tvtime &&exit 1
while true; do
 amixer sset 'CD' 100%
 tvtime ||exit 1
 pidof mencoder &&exit 1 #TODO if not TV?
 amixer sset 'CD' 10%
 $HOME/bin/rec.sh `$HOME/bin/getfreq.sh` & ENC=$!
 trap "kill $ENC; exit" $TRAPS
 #read -p "menc forked $ENC " X
 sleep 10
 #read -p "mpl st" X
 nice -n1 mplayer -framedrop -quiet -fs -osdlevel 3 -vf pp=ac `ls|tail -n1` & MPL=$!  # -fs
 trap "kill $MPL $ENC; exit" $TRAPS
 wait $MPL
 #read -p "mpl ex" X
 while kill $ENC ;do
  echo -n '.' 
  sleep 0.1
 done
 #read -p "menc ex" X
done
trap $TRAPS
